package com.clarence.admin.service.impl;

import java.util.Arrays;
import java.util.List;

import com.clarence.admin.mapper.RolePermissionMapper;
import com.clarence.admin.model.RolePermission;
import com.clarence.admin.service.RolePermissionService;
import com.clarence.base.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * <pre>
 * Description
 * Copyright:	Copyright (c)2014
 * Company:		Sunny
 * Author:		lenovo
 * Version:		1.0
 * Create at:	2017年6月22日 下午10:05:46
 *
 * 修改历史:
 * 日期    作者    版本  修改描述
 * ------------------------------------------------------------------
 *
 * </pre>
 */
@Service("rolePermissionService")
public class RolePermissionServiceImpl extends BaseServiceImpl<RolePermissionMapper, RolePermission, Integer> implements RolePermissionService {


    @Override
	@Autowired
    public void setMapper(RolePermissionMapper mapper) {
        this.mapper = mapper;
    }


    @Override
	@Transactional
    public void allocate(Integer roleId, List<RolePermission> list) {
        mapper.deleteByRoleIds(Arrays.asList(roleId));
        super.save(list);
    }


    @Override
	public List<RolePermission> findByRoleId(Integer roleId) {
        return mapper.findByRoleId(roleId);
    }


    @Override
	public void deleteByPermissionIds(List<Integer> idList) {
        mapper.deleteByPermissionIds(idList);
    }


    @Override
	public void deleteByRoleIds(List<Integer> idList) {
        mapper.deleteByRoleIds(idList);
    }
}
